# -*- coding: UTF-8; indent-tabs-mode:nil; tab-width:4 -*-

# This file is part of DITA DTD Generator.
#
# DITA DTD Generator is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DITA DTD Generator is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DITA DTD Generator.  If not, see <http://www.gnu.org/licenses/>.

import ditagen.dtdgen

class DitaElement(ditagen.dtdgen.Element):
    """Base for DITA elements."""
    _cls = None
    def get_class(self):
        """Get element DITA class."""
        return self._cls

class Type(object):
    """DITA topic type base."""
    _id = None
    _file = None
    _title = None
    _parent = None
    _root = None
    _owner = u"OASIS"
    _required_domains = []
    _alias = None
    def get_id(self):
        """Get topic type ID."""
        return self._id
    def get_file(self):
        """Get topic file name."""
        return self._file
    def get_title(self):
        """Get topic type title."""
        return self._title
    def get_parent(self):
        """Get parent topic type."""
        return self._parent
    def get_root(self):
        """Get topic type root element."""
        return self._root
    def get_owner(self):
        """Get owner of the topic type."""
        return self._owner
    def get_required_domains(self):
        """Get required domains."""
        return self._required_domains
    def get_alias(self):
        """Get topic type this type is alias of."""
        return self._alias

class SpecializationType(Type):
    """Specialization topic type."""
    def __init__(self, id, title, parent, owner=None, file=None, root=None):
        ditagen.dita.Type.__init__(self)
        self._id = id
        self._title = title
        self._parent = parent
        self._owner = owner
        if file is not None:
            self._file = file
        else:
            self._file = id
        if root is not None:
            self._root = root
        else:
            self._root = parent.get_root()

class ShellType(Type):
    """Shell topic type."""
    def __init__(self, id, title, parent, owner=None, file=None):
        ditagen.dita.Type.__init__(self)
        self._id = id
        self._title = title
        self._parent = parent
        self._owner = owner
        if file is not None:
            self._file = file
        else:
            self._file = id
        #if root is not None:
        #    self._root = root
        #else:
        self._root = parent.get_root()


class DomainBase(object):
    """Base class for domains and constraints."""
    _id = None
    _title = None
    _file = None
    _file_suffix = None
    _elements = None
    _parent = []
    _att_id = None
    def get_id(self):
        """Get domain ID."""
        return self._id
    def get_title(self):
        """Get domain title."""
        return self._title
    def get_file(self):
        """Get domain file name."""
        return self._file + self._file_suffix
    def get_elements(self):
        """Get elements domain applies to."""
        return self._elements
    def get_parents(self):
        """Get parent topic types."""
        return self._parent
    def get_att_id(self):
        """Get domain attribute entity ID."""
        if self._att_id is not None:
            return self._att_id
        else:
            return self._id

class Domain(DomainBase):
    """Base class for domains."""
    _file_suffix = u"Domain"
    _fpi_suffix = u" Domain"
    def get_file_name(self, extension):
        return self._file + "Domain." + extension
